package jdo.crud;

import java.io.IOException;
import java.io.PrintWriter;

import javax.jdo.Extent;
import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jdo.entity.Tramway;
import jdo.pmf.PMF;

/**
 * Servlet implementation class ListServlet
 */
@SuppressWarnings("serial")
public class ListServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
			IOException {
		response.setContentType("text/html");
		PersistenceManager pm = PMF.getPersistenceManager();
		PrintWriter page = response.getWriter();
		page.print("<body><h1>List records</h1>");
		page.print("<table border=1><tr><th>ID</th><th>FirstName</th><th>LastName</th><th>HireDate</th><th>Action</th></tr>");
		Extent<Tramway> extent = pm.getExtent(Tramway.class, false);
		for (Tramway record : extent) {
			long id_tram = record.getKey();
			page.print("<tr><td>" + id_tram + "</td><td>" + record.getNom() + "</td><td>"
					+ record.getCoordX() + "</td><td>" + record.getCoordY() + "</td><td>"
					+ "<a href=/delete?tramwayid_tram=" + id_tram + ">delete</a></tr>");
		}
		page.print("</table>");
		pm.close();
		page.print("<a href=/menu.jsp>Back to menu</a></body>");
	}

}
